<template>
  <div>
    <heaDer></heaDer>
    <!-- <div class="topheader">
      <div class="Theadermain">
        <div class="headerimg" @click="back">
          <img src="../../../assets/img20.png" width="100%" />
        </div>
        <div>微信积分系统</div>
        <div style="width: 0.5rem; margin-left: 10px"></div>
      </div>
    </div> -->
    <div class="main">
      <div class="car_list">
        <div
          style="width: 50%; text-align: center; margin: 5% auto"
          v-show="xianshi"
        >
          <van-loading />
        </div>
        <div style="text-align: center; padding: 20px" v-show="yincang">
          <div class="zwxximg">
            <img src="../../../assets/zwxx.png" alt="" />
          </div>
          <div class="zwxx">暂无数据</div>
        </div>
                <template v-for="(item, index) in RecordList1"  >
          <div class="single">
            <div>
              <div class="one_line">{{ item.name }}</div>
              <div style="width: 100%; color: #aeaeae; font-size: 12px">
                开始时间：{{ item.createTime }}
                <div
                  @click="youto(item)"
                  v-if="item.state == 0"
                  class="but"
                  style="
                    background-color: orange;
                    color: rgb(255, 255, 255);
                    padding: 4px 6px;
                    border-radius: 14px;
                    font-size: 14px;
                    float: right;
                    margin-top: -3%;
                  "
                >
                  参与
                </div>
                <div
                  @click="youtoCome(item)"
                  v-if="item.state == 1"
                  class="but"
                  style="
                    background-color: rgb(174, 174, 174);
                    color: rgb(255, 255, 255);
                    padding: 4px 6px;
                    border-radius: 14px;
                    font-size: 14px;
                    float: right;
                    margin-top: -3%;
                  "
                >
                  已投票
                </div>
              </div>
            </div>
            <div style="clear: both"></div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import heaDer from "@/components/page/header/header.vue";
import request from "@/utils/request";
export default {
  components: {
    heaDer,
  },
  data() {
    return {
      RecordList1: [],
      xianshi: true,
      yincang: false,
    };
  },
  created() {
    this.reveal();
    // this.registerDay();
  },

   beforeRouteEnter(to, from, next) {
   next(vm=>{          //  这里的vm指的就是vue实例，可以用来当做this使用
      window.localStorage.setItem("route",to.path);
    })
  },
  methods: {
    registerDay() {
      request({
        url: "/generator/user/front/register",
        method: "get",
      }).then((response) => {
        console.log(response.status, this.data);
        if (response.status == 0) {
          Toast({
            message: response.message,
            iconClass: "glyphicon glyphicon-ok",
          });
        }
      });
    },
    reveal() {
      // let query = { pageNum: 1, pageSize: 4 };
      request({
        url: "/generator/vote/front/list",
        method: "get",
        // params: query,
      }).then((response) => {
        console.log(response.list);
        this.xianshi = false;

        this.RecordList1 = response.list;
        if (this.RecordList1 == "") {
          this.yincang = true;
        } else {
          this.yincang = false;
        }
        console.log(this.RecordList1);

        // alert(JSON.stringify(response.token));
      });
    },
    youto(rows) {
      console.log("点击", rows);
      // let row = JSON.stringify(rows);
      let userId = window.localStorage.getItem("userId");
      this.$router.push({
        name: "Participate",
        query: { row: rows.id, shareUserId: userId },
        params: { time: new Date().getTime() },
      });
    },
    youtoCome(rows) {
      let row = JSON.stringify(rows);

      this.$router.push({ name: "thanksuser", query: { row: row } });
    },
    back() {
      this.$router.go(-1); //返回上一层
    },
  },
};
</script>

<style scoped="scoped">
.zwxximg {
  widows: 100%;
  text-align: center;
}
.zwxx {
  width: 100%;
  text-align: center;
  font-size: 20px;
}
.content {
  overflow: hidden;
  padding: 0 12px 12px;
}
.top {
  height: 40px;
}
.top > div {
  width: 50%;
  height: 100%;
  border-bottom: 1px solid #f8f8f8;
  border-color: #f8f8f8;
}
.active {
  background-color: #ffe090;
  color: orange;
  border-color: #ffe090;
}
.single {
  border-bottom: 1px solid rgb(235, 235, 235);
  /* display: flex; */
  align-items: center;
  width: 90%;
  margin: 0px auto;
  padding: 20px 0px;
}
.single > div:nth-child(1) {
  font-weight: bold;
  font-size: 18px;
  margin-bottom: 8px;
}
.single > div:nth-child(2) {
  font-size: 14px;
  color: #b9b9b9;
}
.one_line{
	font-size: 15px;
	font-weight: bold;
	color: #333;
	margin-bottom: 4%;
}
.but{
   min-width:68px;
   text-align: center;
}
</style>

